package team.se.tms.util;

import team.se.tms.constant.TeachCourseIconConstant;

import java.util.Random;

/**
 * 随机工具类
 *
 * @author winkyle
 * @date 2018/11/6
 */
public class RandomUtil {

    /**
     * 生成多位随机数
     *
     * @param digit 随机数的位数
     * @return 生成的随机数
     * @create on 2018/11/8 by winkyle
     */
    public static Integer generateRandomNum(Integer digit) {
        Random random = new Random();
        int auxiliary = (int) Math.pow(10, digit - 1);
        return random.nextInt(auxiliary * 9) + auxiliary;
    }

    /**
     * 生成多位随机数字符
     *
     * @param digit 随机字符的位数
     * @return 生成的随机字符串
     * @create on 2018/11/8 by winkyle
     */
    public static String generateRandomChar(Integer digit) {
        String code = "";
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        for (int i = 0; i < digit; i++) {
            code += str.charAt(random.nextInt(str.length()));
        }
        return code;
    }

    /**
     * 生成随机背景色
     *
     * @return 生成的随机背景色
     * @create on 2018/12/27by qingx
     */
    public static String generateRandomIcon() {
        String icon = "";
        int number = new Random().nextInt(6);
        icon = TeachCourseIconConstant.teachCourseIconList.get(number);
        return icon;
    }
}
